import 'package:flutter/material.dart';
class Test10 extends StatefulWidget{
    _TestState createState() => _TestState();
}

class _TestState extends State<Test10> {

    Choice _selectedChoices = choices[0];

    void _select(Choice choice){
        setState(() {
            _selectedChoices = choice;
        });
    }

    void _chooseValue(val){
        print(val);
    }

    @override
    Widget build(BuildContext context) {
        return new Scaffold(
            appBar: AppBar(
                title: Text("appbar带下拉菜单"),
                centerTitle: true,
                actions: <Widget>[
                    PopupMenuButton(
                        onSelected: _chooseValue,
                        itemBuilder: (BuildContext context){
                            return [
                                PopupMenuItem(
                                    value: "kkk",
                                    child: Text("kkk"),
                                ),
                                PopupMenuItem(
                                    value: "kkk1",
                                    child: Text("kkk1"),
                                ),
                            ];
                            // return choices.map((Choice choice){
                            //     return PopupMenuItem(
                            //         value: choice,
                            //         child: Text(choice.title),
                            //     );
                            // }).toList();
                        },
                    )
                ],
            ),
            body: Padding(
                padding: EdgeInsets.all(16.0),
                child: ChoiceCard(
                    choice: _selectedChoices,
                ),
            )
        );
    }


}


class Choice{
    const Choice({this.title,this.icon});
    final String title;
    final IconData icon;
}

const List<Choice> choices = const <Choice>[
    const Choice(title: 'Car',icon: Icons.directions_car),
    const Choice(title: 'Bicycle',icon: Icons.directions_bike),
    const Choice(title: 'BOAT', icon: Icons.directions_boat),
    const Choice(title: 'BUS', icon: Icons.directions_bus),
    const Choice(title: 'TRAIN', icon: Icons.directions_railway),
    const Choice(title: 'WALK', icon: Icons.directions_walk),
];

class ChoiceCard extends StatelessWidget{
    ChoiceCard({this.choice});
    final Choice choice;
    @override
    Widget build(BuildContext context){
        return Card(
            color: Colors.white,
            child: Center(
                child: Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                        Icon(choice.icon,size: 128.0,color: Colors.red),
                        Text(choice.title),
                    ],
                ),
            ),
        );
    }

}